package com.ling.pl.security.model;

import com.ling.pl.core.commons.constant.TablePreDef;
import com.ling.pl.core.hibernate.identifier.Ling2UUIDGenerator;
import com.ling.pl.core.model.impl.BaseRelation;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;

import javax.persistence.*;

/**
 * 用户与组织关系
 *
 * @author bo.wang
 * @version 2.0.0
 * @create 2016年3月15日 下午2:32:04
 */
@Entity
@Table(name = UserOrg.TABLE)
public class UserOrg extends BaseRelation {

    public static final String TABLE = TablePreDef.BASEPRE + "USER_ORG";
    public static final String SEQ = TABLE;

    @Id
    @GenericGenerator(name = SEQ + "_GENERATOR", strategy = Ling2UUIDGenerator.STRATEGY_NAME, parameters = {@Parameter(name = "pkColumnValue", value = SEQ)})
    @GeneratedValue(strategy = GenerationType.TABLE, generator = SEQ + "_GENERATOR")
    @Column(name = "USER_ORG_ID", length = 60)
    String id;

    @Column(name = "USERNAME", length = 60, nullable = false)
    String username;

    @Column(name = "ORG_ID", length = 60, nullable = false)
    String orgId;

    @Column(name = "SORT_ORDER")
    Integer sortOrder;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getOrgId() {
        return orgId;
    }

    public void setOrgId(String orgId) {
        this.orgId = orgId;
    }

    public Integer getSortOrder() {
        return sortOrder;
    }

    public void setSortOrder(Integer sortOrder) {
        this.sortOrder = sortOrder;
    }

//    @Override
//    public Serializable getBusinessId() {
//        return getId();
//    }

//    @Override
//    public String toLogString(String operationType, Log log) {
//        ///todo
//        IDao dao = SpringUtil.getBean(BaseDao.BEAN_ID);
//        String logInfo = " 关系如下:";
//        if (getUsername() != null) {
//            if (dao != null) {
//                DefaultUser user = (DefaultUser) dao.get(DefaultUser.class, getUsername());
//                if (user != null) {
//                    logInfo = logInfo + " 用户名:" + user.getUsername() + " 中文名:" + user.getCname();
//                }
//            }
//            logInfo = logInfo + " 用户名:" + getUsername();
//        }
//        if (getOrgId() != null) {
//            if (dao != null) {
//                DefaultOrg org = (DefaultOrg) dao.get(DefaultOrg.class, getOrgId());
//                if (org != null) {
//                    logInfo = logInfo + " 机构名:" + org.getOrgName() + " 机构代码:" + org.getOrgCode();
//                }
//            }
//            logInfo = logInfo + " 机构id:" + getOrgId();
//        }
//        return logInfo;
//    }

}
